<template>
  <cement-content
    :title="userTitle"
    @getData="getUsers"
    @deleteRow="deleteUser"
    @submitUpdate="submitUserUpdate"
    @submitSearchModel="submitUserSearchModel">
  </cement-content>
</template>

<script>
    import cementContent from '@/components/cement-content'
    import {getUsers,deleteUsers,getRole} from '@/api/module/user'
    import {USER_TITLE,FIRST_PAGE} from '@/util/constant'
    import {get} from 'lodash'
    import {mapGetters, mapMutations} from 'vuex'

    export default {
        name: 'index',

        components: {
            cementContent
        },

        data() {
            return {
                userTitle: USER_TITLE,
                tableData: [],
                total: 0
            }
        },

        methods: {
            ...mapMutations([
                'changeTableData',
                'changeTotal',
                'closeDialog',
                'changePageSize'
            ]),

            getUsers() {
                getUsers(this.currentPageGetters - 1, this.pageSizeGetters).then((res) => {
                    // console.log(JSON.stringify(res))
                    let contents = get(res, 'data.data.content', [])
                    contents.forEach((content) => {
                        content.enable = content.enable === true ? '启用' : '停用'
                        content.man = content.man === true ? '男' : '女'
                    })
                    this.changeTableData(get(res,'data.data.content', []))
                    this.changeTotal(get(res, 'data.data.totalElements', 0))
                })
            },

            deleteUser(row) {
                if (get(row, 'id')) {
                    alert('ok')
                    deleteUsers(row['id'])
                }
             },

// 更新员工，暂时没做
            submitUserUpdate() {
                alert('update')
            },

            submitUserSearchModel() {
                this.changePageSize(FIRST_PAGE)
                this.getUsers()

            }
        },

        computed: {
            ...mapGetters([
                'pageSizeGetters',
                'currentPageGetters',
                'searchModelGetters',
                'updateModelGetters'
            ])
        },

        mounted() {
            this.getUsers()
        }

    }
</script>
